package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.utils.poi.ExcelUtilJyjc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.JyjcImportSpsr;
import com.ruoyi.system.service.IJyjcImportSpsrService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 税票收入Controller
 * 
 * @author ruoyi
 * @date 2025-08-19
 */
@RestController
@RequestMapping("/system/spsr")
public class JyjcImportSpsrController extends BaseController
{
    @Autowired
    private IJyjcImportSpsrService jyjcImportSpsrService;

    /**
     * 查询税票收入列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(JyjcImportSpsr jyjcImportSpsr)
    {
        startPage();
        List<JyjcImportSpsr> list = jyjcImportSpsrService.selectJyjcImportSpsrList(jyjcImportSpsr);
        return getDataTable(list);
    }

    /**
     * 导出税票收入列表
     */
    @Anonymous
    @Log(title = "税票收入", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JyjcImportSpsr jyjcImportSpsr)
    {
        List<JyjcImportSpsr> list = jyjcImportSpsrService.selectJyjcImportSpsrList(jyjcImportSpsr);
        ExcelUtil<JyjcImportSpsr> util = new ExcelUtil<JyjcImportSpsr>(JyjcImportSpsr.class);
        util.exportExcel(response, list, "税票收入数据");
    }

    /**
     * 获取税票收入详细信息
     */
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jyjcImportSpsrService.selectJyjcImportSpsrById(id));
    }

    /**
     * 新增税票收入
     */
    @Anonymous
    @Log(title = "税票收入", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JyjcImportSpsr jyjcImportSpsr)
    {
        return toAjax(jyjcImportSpsrService.insertJyjcImportSpsr(jyjcImportSpsr));
    }

    /**
     * 修改税票收入
     */
    @Anonymous
    @Log(title = "税票收入", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JyjcImportSpsr jyjcImportSpsr)
    {
        return toAjax(jyjcImportSpsrService.updateJyjcImportSpsr(jyjcImportSpsr));
    }

    /**
     * 删除税票收入
     */
    @Anonymous
    @Log(title = "税票收入", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jyjcImportSpsrService.deleteJyjcImportSpsrByIds(ids));
    }

    @Anonymous
    @Log(title = "收支汇总", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, String yearyf) throws Exception
    {
        ExcelUtilJyjc<JyjcImportSpsr> util = new ExcelUtilJyjc<JyjcImportSpsr>(JyjcImportSpsr.class);
        List<JyjcImportSpsr> jyjcImportSebsList = util.importExcel(file.getInputStream(),5);

        String message = jyjcImportSpsrService.importJyjcImportSpsr(jyjcImportSebsList, yearyf);
        return success(message);
    }
    @Anonymous
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<JyjcImportSpsr> util = new ExcelUtil<JyjcImportSpsr>(JyjcImportSpsr.class);
        util.importTemplateExcel(response, "收支汇总数据");
    }
}
